#!/bin/sh
# $1 package name+version
# $2 path to tar ball

echo $#
if [ $# != 2 ]; then
  echo usage: $0 package-name+version  path-to-tarball
  exit 1
fi

let cpus=2*`cat /proc/cpuinfo | grep processor | wc -l`
export cpus
echo "CPUs (*2): ${cpus}"

cd /tmp
BUILD=/tmp/mockpp-build.$$
rm -rf $BUILD
mkdir -p $BUILD
rm -rf /tmp/$1

if [ -f $2/$1.tar.bz2 ]; then
  echo "extracting $2/$1.tar.bz2"
  tar xfj $2/$1.tar.bz2
else
 if [ -f $2/$1.tar.gz ]; then
  echo "extracting $2/$1.tar.gz"
  tar xfz $2/$1.tar.gz
 else
  echo no tarball found
  exit 1;
 fi
fi

cd $1
./configure --prefix=$BUILD/_inst1 --enable-unicode --enable-builtin-stl || exit 1
make  -j${cpus} || exit 1
make install    || exit 1
make check      || exit 1
make dist       || exit 1
make doc-dist   || exit 1
make distclean

cd $BUILD
../$1/configure --prefix=$BUILD/_inst2 --enable-doxygen --enable-docbook --disable-builtin-cxxtest --enable-cppunit || exit 1
make  -j${cpus} || exit 1
make install    || exit 1
make check      || exit 1
make dist       || exit 1
make doc-dist   || exit 1

echo $BUILD generated successfully

